//
//  BaseTableViewController.swift
//  XNWeiBo_Swift
//
//  Created by xunan on 16/6/19.
//  Copyright © 2016年 xunan. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorViewDelegate {
    
    // 定义一个变量 保存用户是否登录
    var userLogin = UserAccount.userLogin()
    // 定义属性保存未登录界面
    var visitorView: VisitorView?
    
    override func loadView() {
        
        userLogin ? super.loadView() : setupVisitorView()
        
    }
    
    private func setupVisitorView() {
        
        // 初始化未登录界面
        let customView = VisitorView()
        visitorView = customView
        customView.delegate = self
        view = customView
        
        // 设置导航条未登录按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(self.registerBtnWillClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(self.loginBtnWillClick))

    }
    
    //MARK: - VisitorViewDelegate
    func loginBtnWillClick() {
        let vc = OAuthViewController();
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
    }
    func registerBtnWillClick() {
        print(UserAccount.loadAccount())
    }
    
}



































